
import {
  queryPromotionOrderList
} from "../../../service/jb_promotion_service"
import {
  getMyWorksReq
} from "../../../service/jb_activity_service"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    topSwiperIndex: 0,
    requestData: {
      page: 1,
      limit: 20,
    },
    dataList: [

    ],
    totalCount: 0,
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      page: 1,
      isBottomShow: false,
    })
    this.queryPromotionOrderList('refresh');
  },
  createActivityAction() {
    wx.navigateTo({
      url: '/featurePackage/pages/createMyWorks/createMyWorks',
    })
  },
  queryPromotionOrderList(type) {
    wx.showLoading();
    getMyWorksReq().then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.dataList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          dataList: arr,
          refreshFlag: false,
          isShowLoading: false,
          totalCount: res.data.count,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
      console.error('JJLog:getMyWorksReq', err);
    })
  },
  //去查看或者更新数据
  pushToDetail(e) {
    let item = e.currentTarget.dataset.item;
    if (item.examineStatus == 0) {
      //待审核的
      wx.showToast({
        title: '作品审核中，暂无法操作',
        icon: "none"
      })
      return;
    }
    app.globalData.worksPreview = item;
    wx.navigateTo({
      url: '/featurePackage/pages/createMyWorks/createMyWorks',
    })

  },
  //下拉刷新
  handleRefresh() {
    // TODO
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.queryPromotionOrderList('refresh');
  },
  handleLoadmore() {
    console.log('加载更多');
    return;
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.queryPromotionOrderList()
  },


})